package com.tarena.lbs.message.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.message.pojo.query.MessageQuery;
import com.tarena.lbs.message.pojo.vo.MessageVO;
import com.tarena.lbs.message.service.MessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户消息接口")
@Slf4j
@RestController
@RequiredArgsConstructor
public class MessageController {
    private final MessageService messageService;
    @Operation(summary = "获取新消息列表")
    @PostMapping("/message/selectUserNewMessage")
    public Result<PageResult<MessageVO>> selectNewMessages(MessageQuery query)
            throws BusinessException {
        log.debug("查询新消息列表业务处理,入参:{}",query);
        PageResult<MessageVO> pageResult = messageService.selectNewMessages(query);
        log.debug("查询新消息列表业务处理成功，出参:{}",pageResult.getObjects());
        return new Result<>(pageResult);
    }
    @Operation(summary = "获取全部消息")
    @GetMapping("/message/selectAll")
    public Result<PageResult<MessageVO>> selectAllMessages()
            throws BusinessException{
        log.debug("查询全部消息列表业务处理");
        PageResult<MessageVO> pageResult = messageService.selectAllMessages();
        log.debug("查询全部消息列表业务处理成功，出参:{}",pageResult.getObjects());
        return new Result<>(pageResult);
    }
    @Operation(summary = "删除消息")
    @PostMapping("/message/deleteById")
    public Result<Void> deleteById(Integer messageId)
            throws BusinessException{
        log.debug("删除消息业务处理,入参:{}",messageId);
        messageService.deleteById(messageId);
        log.debug("删除消息业务处理成功");
        return Result.success();
    }
    @Operation(summary = "更新消息为已读")
    @PostMapping("/message/updateMsgStatus")
    public Result<Void> updateMsgStatus(Integer messageId)
            throws BusinessException{
        log.debug("更新消息为已读业务处理,入参:{}",messageId);
        messageService.updateMsgStatus(messageId);
        log.debug("更新消息为已读业务处理成功");
        return Result.success();
    }
}
